﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyDay13.IService;
using MyDay13.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyDay13.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        IRoleService role;
        public RoleController(IRoleService roleService)
        {
            role = roleService;
        }
        [HttpPost]
        [Route("RoleAdd")]
        public IActionResult RoleAdd(D13Role d13Role)
        {
            return Ok(role.RoleAdd(d13Role));
        }
        [HttpGet]
        [Route("RoleDel")]
        public IActionResult RoleDel(string ids)
        {
            return Ok(role.RoleDel(ids));
        }
        [HttpPost]
        [Route("RoleUpt")]
        public IActionResult RoleUpt(D13Role d13Role)
        {
            return Ok(role.RoleUpt(d13Role));
        }
        [HttpGet]
        [Route("RoleShow")]
        public IActionResult RoleShow(int pageindex,int pagesize,string name="",string text="")
        {
            var list = role.RoleShow();
            var count = list.Count();
            if (!string.IsNullOrEmpty(name))
            {
                list = list.Where(x => x.RoleName.Contains(name)).ToList();
            }
            if (!string.IsNullOrEmpty(text))
            {
                list = list.Where(x => x.RoleText.Contains(text)).ToList();
            }
            var slist = list.OrderBy(x => x.RId).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
            return Ok(new {list=slist,total=count,rlist=list });
        }
        [HttpGet]
        [Route("RPManyID")]
        public IActionResult RPManyID(int rid)
        {
            return Ok(role.RPManyID(rid));
        }
        [HttpGet]
        [Route("RPDel")]
        public IActionResult RPDel(int ids)
        {
            return Ok(role.RPDel(ids));
        }
    }
}
